package com.imooc.security.core.social.qq;

import com.imooc.security.core.social.view.ImmocConnectResponseView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;

import com.imooc.security.core.properties.SecurityProperties;
import com.imooc.security.core.social.qq.connect.QQConnectionFactory;
import org.springframework.web.servlet.View;

/**
 * 
 * @author JZH
 * 
 * 只有当imooc.security.social.qq.app-id存在于配置文件中，此配置类才生效
 */
@Configuration
@ConditionalOnProperty(prefix = "imooc.security.social.qq", name = "app-id")
public class QQAutoConfig extends SocialAutoConfigurerAdapter{

	@Autowired
	private SecurityProperties securityProperties;
	
	@Override
	protected ConnectionFactory<?> createConnectionFactory() {
		// TODO Auto-generated method stub
		return new QQConnectionFactory(securityProperties.getSocial().getQq().getProviderId(), securityProperties.getSocial().getQq().getAppId(), securityProperties.getSocial().getQq().getAppSecret());
	}

	/**
	 * 绑定/解绑返回的视图
	 * @return
	 */
	@Bean({"connect/callback.doConnected", "connect/callback.doConnect"})
	public View ImmocConnectResponseView() {
		return new ImmocConnectResponseView();
	}

}
